Create a mock factory that returns jest.fn() stubs for every Repository method. Provide it using the getRepositoryToken(Entity) token from @nestjs/typeorm — this matches the token used internally by @InjectRepository(). Retrieve the mock after compiling the module with module.get(getRepositoryToken(Entity)).
getRepositoryToken(Entity) from @nestjs/typeorm is the correct provider token — matches @InjectRepository().
Create a reusable mock factory so every test file gets a fresh mock object.
Mock createQueryBuilder() with a chainable object that returns this for builder methods.
Use mockResolvedValue() for async repository methods; mockReturnValue() for synchronous ones.
Retrieve the mock with module.get(getRepositoryToken(User)) to configure per-test return values.